package com.gherasoft.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gherasoft.model.CheckListItem;
import com.gherasoft.model.CheckListModel;
import com.gherasoft.view.R;

/**
 * User: sckomoroh
 * Date: 3/12/13
 * Time: 8:31 PM
 */
public class RunCheckListAdapter extends BaseAdapter
{
    private CheckListModel model;
    private Context context;

    public RunCheckListAdapter(Context context, CheckListModel model)
    {
        this.context = context;
        this.model = model;
    }

    public CheckListModel getModel()
    {
        return this.model;
    }

    @Override
    public int getCount()
    {
        return model.getCount();
    }

    @Override
    public Object getItem(int index)
    {
        return this.model.getItem(index);
    }

    @Override
    public long getItemId(int index)
    {
        return index;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup)
    {
        final int index = i;

        CheckListItem item = this.model.getItem(i);

        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.run_check_list_item, null);

        TextView textView = (TextView)view.findViewById(R.id.itemTextView);
        textView.setText(item.getTitle());

        CheckBox checkBox = (CheckBox)view.findViewById(R.id.itemCheckBox);
        checkBox.setChecked(item.isChecked());

        if (item.isChecked())
        {
            textView.setTextColor(R.color.complete_text);
            textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }

        if (item.isFailed())
        {
            textView.setTextColor(Color.RED);
        }

        return view;
    }
}
